package com.kyh.service.sys.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kyh.service.sys.ImgcodeService;
import com.kyh.sys.entity.Imgcode;
import com.kyh.sys.mapper.ImgcodeMapper;
import com.kyh.vo.BootstrapTableVoJA;
import com.kyh.vo.R;

@Service("imgcodeService")
public class ImgcodeServiceImpl implements ImgcodeService {

	@Autowired
	private ImgcodeMapper imgcodeMapper;

	@Override
	@Transactional
	public R add(Imgcode entity) throws Exception {
		
		// 添加数据
		if (imgcodeMapper.insert(entity) != 1) {
			throw new RuntimeException("失败");
		}
		
		return R.ok();
	}

	@Override
	@Transactional
	public R edit(Imgcode entity) throws Exception {
		
		// 更新数据
		if (imgcodeMapper.update(entity) != 1) {
			throw new RuntimeException("失败");
		}
		
		return R.ok();
	}

	@Override
	@Transactional
	public R deleteFalse(Long imgcodeid) throws Exception {
		
		if (imgcodeMapper.deleteFalse(imgcodeid) != 1) {
			throw new RuntimeException("失败");
		}
		
		return R.ok();
	}

	@Override
	public BootstrapTableVoJA search(Imgcode cond) {
		
		List<Map<String, Object>> listMap = cond.queryMap();
		
		int total = cond.count();
		
        BootstrapTableVoJA vo = new BootstrapTableVoJA();
        vo.setRowsByListMap(listMap);
        vo.setTotal(total);
        
        return vo;
	}
}
